unit CheckMem;

interface

implementation

uses
  SysUtils;

const
  FName = 'LostMem.txt';

var
  HPs, HPe: THeapStatus;
  Lost: Integer;
  Report : Text;

initialization
  HPs := GetHeapStatus;

finalization
  HPe := GetHeapStatus;
  Lost := HPe.TotalAllocated - HPs.TotalAllocated;
  DeleteFile(FName);
  if Lost > 0 then
  begin
    AssignFile(Report, FName);
    Rewrite(Report);
    Writeln(Report, Format('LostMem: %d', [Lost]));
    CloseFile(Report);
  end;
end.

